package wait_notify;

import lombok.extern.slf4j.Slf4j;
import util.Sleeper;

@Slf4j(topic = "c.test2")
public class Test2 {
    static final Object lock = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (lock){
                log.debug("获得锁");
                try {
//                    TimeUnit.SECONDS.sleep(2);
                    lock.wait(2);
                    log.debug("释放锁");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("释放锁");
            }
        }).start();

        Sleeper.sleep(1);
        synchronized (lock){
            log.debug("获得锁");
            lock.notify();
            log.debug("释放锁");
        }
    }
}
